cmake_minimum_required (VERSION 3.6)

set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "Installation directory" FORCE)
message(STATUS "CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}")

set(ANDROID_ABI "arm64-v8a")

include_directories(openssl/include)

add_subdirectory(comm comm)
add_subdirectory(boost boost)
add_subdirectory(app app)
add_subdirectory(baseevent baseevent)
add_subdirectory(log xlog)
add_subdirectory(sdt sdt)
add_subdirectory(stn stn)

# for zstd
option(ZSTD_BUILD_STATIC "BUILD STATIC LIBRARIES" ON)
option(ZSTD_BUILD_SHARED "BUILD SHARED LIBRARIES" OFF)
set(ZSTD_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/zstd")
set(LIBRARY_DIR ${ZSTD_SOURCE_DIR}/lib)
include(GNUInstallDirs)
add_subdirectory(zstd/build/cmake/lib zstd)

project (mars)

include(comm/CMakeUtils.txt)

include_directories(.)
include_directories(..)

set(SELF_LIBS_OUT ${CMAKE_SYSTEM_NAME}.out)
set(CMAKE_BUILD_WITH_INSTALL_RPATH true)

if(OHOS)
    find_library(log-lib log)
    find_library(z-lib z)

    link_directories(app baseevent sdt stn comm boost xlog zstd)

    set(SELF_LIB_NAME marsnapi)
    file(GLOB NAPI_INTERFACES napi_interfaces/*.cc)
    file(GLOB DEMO_NAPI_FILES demonapi/*.cpp)
    file(GLOB SELF_SRC_FILES libraries/mars_ohos_sdk/napi/*.cc)
    add_library(${SELF_LIB_NAME} SHARED ${NAPIDEMO_SOURCE_FILES} ${SELF_SRC_FILES} ${DEMO_NAPI_FILES} ${NAPI_INTERFACES})
    install(TARGETS ${SELF_LIB_NAME} LIBRARY DESTINATION ${SELF_LIBS_OUT} ARCHIVE DESTINATION ${SELF_LIBS_OUT})

    link_directories(${SELF_LIBS_OUT})

if(NOT MSVC)
    set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
    set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
endif()
    find_library(CRYPT_LIB crypto PATHS openssl/openssl_lib_android/${ANDROID_ABI} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
    find_library(SSL_LIB ssl PATHS openssl/openssl_lib_android/${ANDROID_ABI} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
    target_link_libraries(${SELF_LIB_NAME} PUBLIC
                        libace_napi.z.so
                        libc++.a
                        libhilog_ndk.z.so
                        stn
                        sdt
                        app
                        baseevent
                        comm
                        mars-boost
                        xlog
                        libzstd_static
                        ${SSL_LIB}
                        ${CRYPT_LIB})

elseif(APPLE)

endif()





